package com.brush.brushbasicapi.controller;

import com.brush.brushcommon.annotation.NoReSubmit;
import com.brush.brushcommon.common.BaseController;
import com.brush.brushcommon.common.basic.pojo.SystemQuestionBank;
import com.brush.brushcommon.common.sys.pojo.User;
import com.brush.brushcommon.dto.basic.SystemQuestionBankFDto;
import com.brush.brushcommon.common.basic.service.SystemQuestionBankService;
import com.brush.brushcommon.dto.Result;
import io.swagger.v3.oas.annotations.OpenAPI31;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 系统题库 前端控制器
 * </p>
 *
 * @author debug
 * @since 2024-07-14
 */
@RestController
@RequestMapping("/systemQuestionBank")
@Tag(name = "系统题库")
public class SystemQuestionBankController extends BaseController {


    @Resource
    private SystemQuestionBankService systemQuestionBankService;


    @Operation(summary = "系统题库列表")
    @Parameters({
            @Parameter(name = "Authorization", description = "请求token", required = true, in = ParameterIn.HEADER)
    })
    @PostMapping("questionBankList")
    public Result questionBankList(@RequestBody SystemQuestionBankFDto systemQuestionBankFDto) {
        return systemQuestionBankService.selectQuestionBankList(systemQuestionBankFDto);
    }


    @Operation(summary = "添加系统题库")
    @Parameters({
            @Parameter(name = "Authorization", description = "请求token", required = true, in = ParameterIn.HEADER),
    })
    @PostMapping("/addQuestionBank")
    public Result addQuestionBank(@RequestBody SystemQuestionBank systemQuestionBank) {
        User userInfo = getUserInfo();
        if (userInfo.getType() != 1) {
            return Result.fail(500, "无权限操作~");
        }
        systemQuestionBank.setGmtFounder(userInfo.getId());
        return systemQuestionBankService.addQuestionBank(systemQuestionBank);
    }

    @Operation(summary = "修改系统题库")
    @Parameters({
            @Parameter(name = "Authorization", description = "请求token", required = true, in = ParameterIn.HEADER),
    })
    @PutMapping("/updateQuestionBank")
    public Result updateQuestionBank(@RequestBody SystemQuestionBank systemQuestionBank) {
        User userInfo = getUserInfo();
        if (userInfo.getType() != 1) {
            return Result.fail(500, "无权限操作~");
        }
        return systemQuestionBankService.updateQuestionBank(systemQuestionBank);
    }

    @Operation(summary = "删除系统题库")
    @Parameters({
            @Parameter(name = "Authorization", description = "请求token", required = true, in = ParameterIn.HEADER),
    })
    @DeleteMapping("/deleteQuestionBank")
    @NoReSubmit
    public Result deleteQuestionBank(@RequestParam("ids") List<String> ids) {
        User userInfo = getUserInfo();
        if (userInfo.getType() != 1) {
            return Result.fail(500, "无权限操作~");
        }
        return systemQuestionBankService.deleteQuestionBank(ids);
    }
}
